#使用unicode编码，避免中文乱码
#不使用chess模块，自己实现棋盘、棋子、走法、胜负判定等功能

class ChessBoard:
    def __init__(self):
        self.board = [['.' for i in range(8)] for j in range(8)]
        self.board[3][3] = '♜'
        self.board[4][4] = '♞'
        self.board[3][4] = '♝'
        self.board[4][3] = '♛'
        self.board[2][3] = '♚'
        self.board[3][2] = '♝'
        self.board[2][4] = '♚'
        self.board[4][2] = '♛'
        self.board[1][3] = '♟'
        self.board[3][1] = '♞'
        self.board[1][4] = '♟'
        self.board[4][1] = '♜'
        self.board[0][3] = '♙'
        self.board[3][0] = '♘'
        self.board[0][4] = '♙'
        self.board[4][0] = '♗'
        self.board[0][2] = '♖'
        self.board[2][0] = '♕'
        self.board[0][5] = '♘'
        self.board[5][0] = '♗'
        self.board[0][1] = '♖'
        self.board[1][0] = '♕'
        self.board[0][6] = '♙'
        self.board[6][0] = '♖'
        self.board[1][6] = '♟'
        self.board[6][1] = '♞'
        self.board[2][6] = '♚'
        self.board[6][2] = '♝'
        self.board[3][6] = '♛'
        self.board[6][3] = '♜'
        self.board[4][6] = '♝'
        self.board[6][4] = '♚'
        self.board[5][6] = '♛'
        self.board[6][5] = '♜'
        self.board[6][6] = '♝'
        self.board[6][7] = '♚'
        self.board[7][6] = '♛'
        self.board[6][8] = '♜'
        self.board[8][6] = '♝'
        self.board[7][7] = '♚'
        self.board[7][8] = '♛'
        self.board[8][7] = '♜'
        self.board[8][8] = '♝'

    def __str__(self):
        s = ''
        for i in range(8):
            for j in range(8):
                s += self.board[i][j] + '|'
            s = s[:-1] + '\n'
        return s

    def move(self, start, end):
        if self.board[start[0]][start[1]] == '.':
            return False
        if self.board[end[0]][end[1]] != '.':
            return False
        if abs(start[0] - end[0]) == 2 and abs(start[1] - end[1]) == 2:
            if self.board[start[0]+1][start[1]+1] == self.board[start[0]][start[1]] and self.board[start[0]+1][start[1]+1] == self.board[end[0]][end[1]]:
                self.board[start[0]+1][start[1]+1] = '.'
                self.board[end[0]][end[1]] = self.board[start[0]][start[1]]
                return True
            elif self.board[start[0]+1][start[1]-1] == self.board[start[0]][start[1]] and self.board[start[0]+1][start[1]-1] == self.board[end[0]][end[1]]:
                self.board[start[0]+1][start[1]-1] = '.'
                self.board[end[0]][end[1]] = self.board[start[0]][start[1]]
                return True
            elif self.board[start[0]-1][start[1]+1] == self.board[start[0]][start[1]] and self.board[start[0]-1][start[1]+1] == self.board[end[0]][end[1]]:
                self.board[start[0]-1][start[1]+1] = '.'
                self.board[end[0]][end[1]] = self.board[start[0]][start[1]]
                return True
            elif self.board[start[0]-1][start[1]-1] == self.board[start[0]][start[1]] and self.board[start[0]-1][start[1]-1] == self.board[end[0]][end[1]]:
                self.board[start[0]-1][start[1]-1] = '.'
                self.board[end[0]][end[1]] = self.board[start[0]][start[1]]
                return True
        elif abs(start[0] - end[0]) == 1 and abs(start[1] - end[1]) == 1:
            self.board[end[0]][end[1]] = self.board[start[0]][start[1]]
            self.board[start[0]][start[1]] = '.'
            return True
        return False

    def check_win(self):
        for i in range(8):
            for j in range(8):
                if self.board[i][j] == '♜':
                    if self.board[i+1][j+1] == '♞' and self.board[i+2][j+2] == '♝' and self.board[i+3][j+3] == '♛' and self.board[i+4][j+4] == '♚' and self.board[i+5][j+5] == '♝' and self.board[i+6][j+6] == '♞' and self.board[i+7][j+7] == '♜':
                        return 'white'
                    elif self.board[i-1][j-1] == '♞' and self.board[i-2][j-2] == '♝' and self.board[i-3][j-3] == '♛' and self.board[i-4][j-4] == '♚' and self.board[i-5][j-5] == '♝' and self.board[i-6][j-6] == '♞' and self.board[i-7][j-7] == '♜':
                        return 'white'
                elif self.board[i][j] == '♞':
                    if self.board[i+1][j-1] == '♝' and self.board[i+2][j-2] == '♚' and self.board[i+3][j-3] == '♛' and self.board[i+4][j-4] == '♝' and self.board[i+5][j-5] == '♚' and self.board[i+6][j-6] == '♝' and self.board[i+7][j-7] == '♞':
                        return 'white'
                    elif self.board[i-1][j+1] == '♝' and self.board[i-2][j+2] == '♚' and self.board[i-3][j+3] == '♛' and self.board[i-4][j+4] == '♝' and self.board[i-5][j+5] == '♚' and self.board[i-6][j+6] == '♝' and self.board[i-7][j+7] == '♞':
                        return 'white'
                elif self.board[i][j] == '♝':
                    if self.board[i+1][j+1] == '♚' and self.board[i+2][j+2] == '♛' and self.board[i+3][j+3] == '♜' and self.board[i+4][j+4] == '♝' and self.board[i+5][j+5] == '♚' and self.board[i+6][j+6] == '♛' and self.board[i+7][j+7] == '♝':
                        return 'white'
                    elif self.board[i-1][j-1] == '♚' and self.board[i-2][j-2] == '♛' and self.board[i-3][j-3] == '♜' and self.board[i-4][j-4] == '♝' and self.board[i-5][j-5] == '♚' and self.board[i-6][j-6] == '♛' and self.board[i-7][j-7] == '♝':
                        return 'white'
                elif self.board[i][j] == '♛':
                    if self.board[i+1][j-1] == '♝' and self.board[i+2][j-2] == '♚' and self.board[i+3][j-3] == '♜' and self.board[i+4][j-4] == '♛' and self.board[i+5][j-5] == '♝' and self.board[i+6][j-6] == '♚' and self.board[i+7][j-7] == '♛':
                        return 'white'
                    elif self.board[i-1][j+1] == '♝' and self.board[i-2][j+2] == '♚' and self.board[i-3][j+3] == '♜' and self.board[i-4][j+4] == '♛' and self.board[i-5][j+5] == '♝' and self.board[i-6][j+6] == '♚' and self.board[i-7][j+7] == '♛':
                        return 'white'
                elif self.board[i][j] == '♚':
                    if self.board[i+1][j+1] == '♛' and self.board[i+2][j+2] == '♜' and self.board[i+3][j+3] == '♝' and self.board[i+4][j+4] == '♚' and self.board[i+5][j+5] == '♛' and self.board[i+6][j+6] == '♜' and self.board[i+7][j+7] == '♚':
                        return 'white'
                    elif self.board[i-1][j-1] == '♛' and self.board[i-2][j-2] == '♜' and self.board[i-3][j-3] == '♝' and self.board[i-4][j-4] == '♚' and self.board[i-5][j-5] == '♛' and self.board[i-6][j-6] == '♜' and self.board[i-7][j-7] == '♚':
                        return 'white'
                elif self.board[i][j] == '♟':
                    if self.board[i+1][j+1] == '♞' and self.board[i+2][j+2] == '♝' and self.board[i+3][j+3] == '♚' and self.board[i+4][j+4] == '♛' and self.board[i+5][j+5] == '♚' and self.board[i+6][j+6] == '♝' and self.board[i+7][j+7] == '♞':
                        return 'white'
                    elif self.board[i-1][j-1] == '♞' and self.board[i-2][j-2] == '♝' and self.board[i-3][j-3] == '♚' and self.board[i-4][j-4] == '♛' and self.board[i-5][j-5] == '♚' and self.board[i-6][j-6] == '♝' and self.board[i-7][j-7] == '♞':
                        return 'white'
                elif self.board[i][j] == '♙':
                    if self.board[i+1][j+1] == '♘' and self.board[i+2][j+2] == '♗' and self.board[i+3][j+3] == '♖' and self.board[i+4][j+4] == '♕' and self.board[i+5][j+5] == '♖' and self.board[i+6][j+6] == '♗' and self.board[i+7][j+7] == '♘':
                        return 'white'
                    elif self.board[i-1][j-1] == '♘' and self.board[i-2][j-2] == '♗' and self.board[i-3][j-3] == '♖' and self.board[i-4][j-4] == '♕' and self.board[i-5][j-5] == '♖' and self.board[i-6][j-6] == '♗' and self.board[i-7][j-7] == '♘':
                        return 'white'
                elif self.board[i][j] == '♘':
                    if self.board[i+1][j-1] == '♕' and self.board[i+2][j-2] == '♖' and self.board[i+3][j-3] == '♗' and self.board[i+4][j-4] == '♘' and self.board[i+5][j-5] == '♗' and self.board[i+6][j-6] == '♖' and self.board[i+7][j-7] == '♕':
                        return 'white'
                    elif self.board[i-1][j+1] == '♕' and self.board[i-2][j+2] == '♖' and self.board[i-3][j+3] == '♗' and self.board[i-4][j+4] == '♘' and self.board[i-5][j+5] == '♗' and self.board[i-6][j+6] == '♖' and self.board[i-7][j+7] == '♕':
                        return 'white'
                elif self.board[i][j] == '♗':
                    if self.board[i+1][j+1] == '♖' and self.board[i+2][j+2] == '♕' and self.board[i+3][j+3] == '♘' and self.board[i+4][j+4] == '♙' and self.board[i+5][j+5] == '♘' and self.board[i+6][j+6] == '♕' and self.board[i+7][j+7] == '♖':
                        return 'white'
                    elif self.board[i-1][j-1] == '♖' and self.board[i-2][j-2] == '♕' and self.board[i-3][j-3] == '♘' and self.board[i-4][j-4] == '♙' and self.board[i-5][j-5] == '♘' and self.board[i-6][j-6] == '♕' and self.board[i-7][j-7] == '♖':
                        return 'white'
                elif self.board[i][j] == '♖':
                    if self.board[i+1][j-1] == '♘' and self.board[i+2][j-2] == '♙' and self.board[i+3][j-3] == '♗' and self.board[i+4][j-4] == '♕' and self.board[i+5][j-5] == '♗' and self.board[i+6][j-6] == '♙' and self.board[i+7][j-7] == '♘':
                        return 'white'
                    elif self.board[i-1][j+1] == '♘' and self.board[i-2][j+2] == '♙' and self.board[i-3][j+3] == '♗' and self.board[i-4][j+4] == '♕' and self.board[i-5][j+5] == '♗' and self.board[i-6][j+6] == '♙' and self.board[i-7][j+7] == '♘':
                        return 'white'
                elif self.board[i][j] == '♕':
                    if self.board[i+1][j+1] == '♙' and self.board[i+2][j+2] == '♘' and self.board[i+3][j+3] == '♖' and self.board[i+4][j+4] == '♗' and self.board[i+5][j+5] == '♖' and self.board[i+6][j+6] == '♘' and self.board[i+7][j+7] == '♙':
                        return 'white'
                    elif self.board[i-1][j-1] == '♙' and self.board[i-2][j-2] == '♘' and self.board[i-3][j-3] == '♖' and self.board[i-4][j-4] == '♗' and self.board[i-5][j-5] == '♖' and self.board[i-6][j-6] == '♘' and self.board[i-7][j-7] == '♙':
                        return 'white'
                elif self.board[i][j] == '♞':
                    if self.board[i+1][j+1] == '♟' and self.board[i+2][j+2] == '♝' and self.board[i+3][j+3] == '♚' and self.board[i+4][j+4] == '♛' and self.board[i+5][j+5] == '♚' and self.board[i+6][j+6] == '♝' and self.board[i+7][j+7] == '♟':
                        return 'white'
                    elif self.board[i-1][j-1] == '♟' and self.board[i-2][j-2] == '♝' and self.board[i-3][j-3] == '♚' and self.board[i-4][j-4] == '♛' and self.board[i-5][j-5] == '♚' and self.board[i-6][j-6] == '♝' and self.board[i-7][j-7] == '♟':
                        return 'white'
                elif self.board[i][j] == '♝':
                    if self.board[i+1][j-1] == '♞' and self.board[i+2][j-2] == '♟' and self.board[i+3][j-3] == '♚' and self.board[i+4][j-4] == '♛' and self.board[i+5][j-5] == '♚' and self.board[i+6][j-6] == '♟' and self.board[i+7][j-7] == '♞':
                        return 'white'
                    elif self.board[i-1][j+1] == '♞' and self.board[i-2][j+2] == '♟' and self.board[i-3][j+3] == '♚' and self.board[i-4][j+4] == '♛' and self.board[i-5][j+5] == '♚' and self.board[i-6][j+6] == '♟' and self.board[i-7][j+7] == '♞':
                        return 'white'
                elif self.board[i][j] == '♜':
                    if self.board[i+1][j+1] == '♛' and self.board[i+2][j+2] == '♝' and self.board[i+3][j+3] == '♚' and self.board[i+4][j+4] == '♜' and self.board[i+5][j+5] == '♚' and self.board[i+6][j+6] == '♝' and self.board[i+7][j+7] == '♛':
                        return 'white'
                    elif self.board[i-1][j-1] == '♛' and self.board[i-2][j-2] == '♝' and self.board[i-3][j-3] == '♚' and self.board[i-4][j-4] == '♜' and self.board[i-5][j-5] == '♚' and self.board[i-6][j-6] == '♝' and self.board[i-7][j-7] == '♛':
                        return 'white'
                elif self.board[i][j] == '♚':
                    if self.board[i+1][j-1] == '♜' and self.board[i+2][j-2] == '♛' and self.board[i+3][j-3] == '♝' and self.board[i+4][j-4] == '♚' and self.board[i+5][j-5] == '♝' and self.board[i+6][j-6] == '♛' and self.board[i+7][j-7] == '♜':
                        return 'white'
                    elif self.board[i-1][j+1] == '♜' and self.board[i-2][j+2] == '♛' and self.board[i-3][j+3] == '♝' and self.board[i-4][j+4] == '♚' and self.board[i-5][j+5] == '♝' and self.board[i-6][j+6] == '♛' and self.board[i-7][j+7] == '♜':
                        return 'white'
                elif self.board[i][j] == '♝':
                    if self.board[i+1][j-1] == '♚' and self.board[i+2][j-2] == '♜' and self.board[i+3][j-3] == '♛' and self.board[i+4][j-4] == '♝' and self.board[i+5][j-5] == '♛' and self.board[i+6][j-6] == '♜' and self.board[i+7][j-7] == '♚':
                        return 'white'
                    elif self.board[i-1][j+1] == '♚' and self.board[i-2][j+2] == '♜' and self.board[i-3][j+3] == '♛' and self.board[i-4][j+4] == '♝' and self.board[i-5][j+5] == '♛' and self.board[i-6][j+6] == '♜' and self.board[i-7][j+7] == '♚':
                        return 'white'
                elif self.board[i][j] == '♛':
                    if self.board[i+1][j+1] == '♜' and self.board[i+2][j+2] == '♚' and self.board[i+3][j+3] == '♝' and self.board[i+4][j+4] == '♛' and self.board[i+5][j+5] == '♝' and self.board[i+6][j+6] == '♚' and self.board[i+7][j+7] == '♜':
                        return 'white'
                    